#include "imagelabel.h"

ImageLabel::ImageLabel()
	: QLabel(0)
{

}

ImageLabel::~ImageLabel()
{

}

void ImageLabel::mouseDoubleClickEvent( QMouseEvent * e ) {
	if(e->button() == Qt::LeftButton)
		emit doubleClicked();
	QLabel::mouseDoubleClickEvent(e);
}

void ImageLabel::mouseMoveEvent(QMouseEvent* e) {
	QLabel::mouseMoveEvent(e);
}

void ImageLabel::wheelEvent(QWheelEvent* e) {
	emit wheelMoved(e->delta());
	QLabel::wheelEvent(e);
}

void ImageLabel::mousePressEvent( QMouseEvent * e ) {
	if(e->button() == Qt::LeftButton) {
		m_pressed = true;
		m_startX = e->x();
		m_startY = e->y();
	} else
		m_pressed = false;
	emit pressed();
}

void ImageLabel::mouseReleaseEvent( QMouseEvent * e ) {
	if (m_pressed && e->button() == Qt::LeftButton && hitLabel(e->pos()) && (e->x() != m_startX || e->y() != m_startY))
		emit dragFinished(e->x() - m_startX, e->y() - m_startY);
	else if(m_pressed && e->button() == Qt::LeftButton && hitLabel(e->pos()))
		emit clicked();
	m_pressed = false;
	emit released();
}

void ImageLabel::enterEvent( QEvent *e ) {
	QLabel::enterEvent(e);
	emit mouseOver();
}

void ImageLabel::leaveEvent( QEvent *e ) {
	QLabel::leaveEvent(e);
	emit mouseOut();
}

bool ImageLabel::hitLabel( const QPoint & p ){
	return rect().contains(p);
}